package sv.ues.fia.adminperfildocentes.adapter;

import java.util.ArrayList;
import java.util.HashMap;

import sv.ues.fia.adminperfildocentes.R;
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class ListExperienciaAdapter extends BaseAdapter {
	ArrayList<HashMap<String, String>> listExperienciaDocente;
	private Activity activity;
	
	public ListExperienciaAdapter(Activity activity, ArrayList<HashMap<String, String>> listExperienciaDocente) {
		super();
		this.listExperienciaDocente = listExperienciaDocente;
		this.activity = activity;
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return listExperienciaDocente.size();
	}

	@Override
	public String getItem(int position) {
		// TODO Auto-generated method stub
		return listExperienciaDocente.get(position).get("DENOMINACION_SOCIAL");
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return Long.valueOf(listExperienciaDocente.get(position).get("IDEXPERIENCIA"));
	}
	
	
	public String getItemCargo(int position) {
		// TODO Auto-generated method stub
		return listExperienciaDocente.get(position).get("NOMBRE");
	}

	
	public String getItemPeriodo(int position) {
		// TODO Auto-generated method stub
		return listExperienciaDocente.get(position).get("PERIODO");
	}

	public static class ViewHolder
	{
		public TextView txtViewEmpresa;
		public TextView txtViewCargo;
		public TextView txtViewPeriodo;
		public TextView txtViewId;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder view;
		LayoutInflater inflator = activity.getLayoutInflater();
		
		if(convertView==null)
		{
			view = new ViewHolder();
			convertView = inflator.inflate(R.layout.list_row_experiencia_docente, null);
			
			view.txtViewId = (TextView) convertView.findViewById(R.id.idRow);
			view.txtViewEmpresa = (TextView) convertView.findViewById(R.id.empresaRow);
			view.txtViewCargo = (TextView) convertView.findViewById(R.id.cargoRow);
			view.txtViewPeriodo = (TextView) convertView.findViewById(R.id.periodoRow);
			
			convertView.setTag(view);
		}
		else
		{
			view = (ViewHolder) convertView.getTag();
		}
		
		view.txtViewId.setText(listExperienciaDocente.get(position).get("IDEXPERIENCIA"));
		view.txtViewEmpresa.setText(listExperienciaDocente.get(position).get("DENOMINACION_SOCIAL"));
		view.txtViewCargo.setText("Cargo: "+listExperienciaDocente.get(position).get("NOMBRE"));
		view.txtViewPeriodo.setText(listExperienciaDocente.get(position).get("PERIODO"));
		
		
		
		return convertView;
	}

}
